export default {
  methods: {
    // 二进制blob文件流下载
    blobFileLoad(stream, fileName, suffix = '.xlsx') {
      if (stream && fileName) {
        const blob = new Blob([stream])
        const fullName = `${fileName + suffix}`
        // IE10+ 浏览器特殊处理
        if (window.navigator.msSaveBlob) {
          window.navigator.msSaveBlob(blob, fullName)
        } else {
          const href = window.URL.createObjectURL(blob)
          const a = document.createElement('a')
          a.href = href
          a.download = fullName
          document.body.appendChild(a)
          a.click()
          window.URL.revokeObjectURL(href)
          document.body.removeChild(a)
        }
      } else {
        this.$message.error('暂无数据，无法导出！')
      }
    },
    open(url, params, title = '_blank') {
      if (!url) return
      if (!params || typeof params !== 'object') {
        title = params
      } else {
        url =
          url +
          Object.entries(params)
            .map(i => i.join('='))
            .join('&')
      }
      window.open(url, title)
    }
  }
}
